package flash.events
{
	public class EventDispatcher
	{
		protected var messageMethods:Object = new Object();
		public function EventDispatcher()
		{
		}
		public function dispatchEvent(e:Event):void
		{
			var funs:Array = messageMethods[e.type];
			e.target = e.currentTarget = this;
			if(funs)
			{
				for(var i:int=0;i<funs.length;i++)
				{
					funs[i](e);
				}
			}
		}
		public function addEventListener(type:String,method:Function):void
		{
			var funs:Array = messageMethods[type];
			if(!funs)
			{
				funs = [];
			}
			funs.push(method);
			messageMethods[type] = funs;
		}
		public function hasEventListener (type:String):Boolean
		{
			return messageMethods[type] != null;
		}
		public function removeEventListener (type:String,method:Function):void
		{			
			var funs:Array = messageMethods[type];
			if(funs != null)
			{
				var newFuns:Array = [];
				for(var i:int=0;i<funs.length;i++)
				{
					if(funs[i] != method)
					{
						newFuns.push(funs[i]);
					}
				}
				messageMethods[type] = newFuns;
			}
		}
	}
}